Previous Up Next

Getting Started

Cool source files have extension \(\rm .cl\). The programming projects will also define other file formats related to Cool but they are not officially part of the language specification.

You can obtain the Cool interpreter \(\rm cool\) from the course website. To interpret (i.e., run) a Cool program:

cool file.cl 

This official version is often called the \(\it reference\ implementation\) and you are encouraged to use it as a point of comparison when you are designing and testing parts of the course project. The reference Cool interpreter has been specifically structured so that you can run the various stages (i.e., lexing, parsing, type-checking and interpreting) independently. This power is useful for PA2 through PA5.

The Cool interpreter has an number of command-line options:

--lex
This option causes Cool to stop after lexing and produce a new file, \(\rm file.cl \HY lex\), which contains the lexed tokens in a simple interchange format. Handy for PA2.
--unlex
This option causes Cool to undo lexing and produce \(\rm file.cl2\) (a Cool source file) from the lexed tokens. This is usually used as a debugging aid for PA2 by feeding Cool a \(\rm file.cl \HY lex\) file produced by \(\it your\ lexer\) from \(\rm file.cl\) and then comparing \(\rm file.cl2\) to the original \(\rm file\).cl.
--parse
This option causes Cool to stop after parsing and produce a new file, \(\rm file.cl \HY ast\), which contains the abstract syntax tree in a simple interchange format. Handy for PA3.
--unparse
This option causes Cool to undo parsing and produce \(\rm file.cl3\) (a Cool source file) from the abstract syntax tree. This is usually used as a debugging aid for PA3 by feeding Cool a \(\rm file.cl \HY ast\) file produced by your parser from \(\rm file.cl\) and then comparing \(\rm file.cl3\) to the original \(\rm file.cl\).
--type
This option causes Cool to stop after type checking and semantic analysis and produce a new file, \(\rm file.cl \HY type\), which contains the class mapping and implementation mapping in a simple interchange format. Handy for PA4.
--class-map
This option causes Cool to stop after type checking and semantic analysis and produce a new file, \(\rm file.cl \HY type\), which contains the class mapping only in a simple interchange format. Handy for the PA4 Checkpoint (WA4).
--imp-map
This option causes Cool to stop after type checking and semantic analysis and produce a new file, \(\rm file.cl \HY type\), which contains the implementation mapping only in a simple interchange format. Handy for the rest of PA4.
--parent-map
This option causes Cool to stop after type checking and semantic analysis and produce a new file, \(\rm file.cl \HY type\), which contains the parent mapping only in a simple interchange format. Handy for the rest of PA4.
--out \(\it newname\)
Causes Cool to produce \(\it newname.cl\) (or \(\rm .cl \HY ast\), or whatever) instead of \(\rm file.cl\).

You may encounter other University uses of Cool on the web that mention programs such as \(\rm coolc\) and \(\rm spim\). Those tool are used for a course on compilers; this is a course on interpreters. We will not use \(\rm coolc\) or \(\rm spim\). In addition, we use a slightly different version of the Cool language specification, so comparing results against external tools may not be helpful.

Previous Up Next